/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =====================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =====================================================
 *   $Id: CellImage.java 580 2010-07-26 12:26:56Z YongPeng $
 *   $LastChangedDate: 2010-07-26 12:26:56 +0000 (Mon, 26 Jul 2010) $
 *   $LastChangedBy: YongPeng $
 *--------------------------------------------------------------------------
 */
package battlefield.entity;

import java.io.Serializable;

/**
 *
 * @author Harry Nguyen
 */
public class CellImage implements Serializable {

    private String source;
    private int x;
    private int y;
    private int width;
    private int height;

    /**
     * Construct the CellImage object with the following param
     *
     * @param source path to the image
     * @param  x the x position of the image
     * @param  y the y position of the image
     * @param  width width of the Cell
     * @param  height height of the Cell
     */
    public CellImage(String source, int x, int y, int width, int height) {
        this.source = source;
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    /**
     * Returns the path to the image
     *
     * @return the path to the image
     */
    public String getSource() {
        return source;
    }

    /**
     * Returns the x position of the image
     * 
     * @return      int the x position of the image
     */
    public int getX() {
        return x;
    }

    /**
     * Returns the y position of the image
     *
     * @return      int the y position of the image
     */
    public int getY() {
        return y;
    }

    /**
     * Returns the width of the image
     *
     * @return      int the width of the image
     */
    public int getWidth() {
        return width;
    }

    /**
     * Returns the height of the image
     *
     * @return      int the height of the image
     */
    public int getHeight() {
        return height;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (!(obj instanceof CellImage)) {
            return false;
        }

        CellImage ci = (CellImage) obj;

        if (this.getSource() == null || !this.getSource().equals(ci.getSource())) {
            return false;
        }

        return this.getX() == ci.getX() && this.getY() == ci.getY() && this.getWidth() == ci.getWidth() && this.getHeight() == ci.getHeight();
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 43 * hash + (this.source != null ? this.source.hashCode() : 0);
        hash = 43 * hash + this.x;
        hash = 43 * hash + this.y;
        hash = 43 * hash + this.width;
        hash = 43 * hash + this.height;
        return hash;
    }
}
